package com.spring.shops.admin.controller.VIP;

import com.spring.shops.model.entity.TzUser;
import com.spring.shops.model.result.VipResult;
import com.spring.shops.model.vo.VipPageVo;
import com.spring.shops.service.VipUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/user")
public class VipController {

    @Resource
    private VipUserService vipUserService;

    @GetMapping("page")
    public VipResult Page(@RequestParam("t") long t,
                          @RequestParam("current") String current,
                          @RequestParam("size") String size,
                          @RequestParam(value = "nickName", defaultValue = "") String nickName,
                          @RequestParam(value = "status", defaultValue = "2") int status) {

        VipPageVo vipPageVo = new VipPageVo();
        vipPageVo.setCurrent(Integer.parseInt(current));
        vipPageVo.setSize(Integer.parseInt(size));
        VipPageVo vipPageVo1 = vipUserService.selectByPage(vipPageVo,nickName,status);
        return VipResult.vipUserResult(vipPageVo1);
    }


    @GetMapping("/info/{userId}")
    public VipResult info(@PathVariable("userId") String userId){
        TzUser tzUser = vipUserService.selectByUserId(userId);
        return VipResult.infoResult(tzUser);
    }

    @PutMapping
    public VipResult update(@RequestBody TzUser tzUser){
        int i = vipUserService.updateStatus(tzUser);
        return VipResult.updateResult();
    }

}

